package com.itheima.service.imp;

import com.itheima.common.R;
import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Clazz;
import com.itheima.service.EmpService;
import com.itheima.service.ReportService;
import com.itheima.vo.ReportClazzDataVo;
import com.itheima.vo.ReportJobVo;
import com.itheima.vo.ReportVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service

public class ReportServiceImpl implements ReportService {
    @Autowired
    EmpMapper empMapper;
    @Autowired
    StudentMapper studentMapper;
    @Autowired
    ClazzMapper clazzMapper;

    @Override
    public List<ReportVo> empGenderData() {
        List<ReportVo>list=empMapper.reportgender();
        for(ReportVo reportVo : list) {
            reportVo.setName(reportVo.getName().equals("1")? "男":"女");
        }

        return list;
    }

    @Override
    public ReportJobVo empJobData() {

        ReportJobVo reportJobVo=new ReportJobVo();
        List<Integer>job=empMapper.reportjob();
        reportJobVo.setDataList(empMapper.reportjobdata());
        Map<Integer,String> map=new HashMap<>();
        map.put(1,"班主任");
        map.put(2,"讲师");
        map.put(3,"学工主管");
        map.put(4,"教研主管");
        map.put(5,"咨询师");
        map.put(null,"其他");

        List<String>list=new ArrayList<>();
        log.info("job"+job);
       for(int i=0;i< job.size();i++){
           list.add(map.get(job.get(i)));
           log.info("map.get"+map.get(job.get(i)));
       }

       reportJobVo.setJobList(list);
        return reportJobVo;
    }

    @Override
    public List<ReportVo> reportdegree() {
       Map<Integer,String>map=new HashMap<>();
       map.put(1,"初中");
       map.put(2,"高中");
       map.put(3,"大专");
       map.put(4,"本科");
       map.put(5,"硕士");
       map.put(6,"博士");
       List<Integer>degreelist=studentMapper.reportdegree();
       List<Integer>countdegree=studentMapper.reportcountdegree();
       List<ReportVo>list=new ArrayList<>();
       for(int i=0;i<degreelist.size();i++){
           ReportVo reportVo=new ReportVo();
           reportVo.setName(map.get(degreelist.get(i)));
           reportVo.setValue(countdegree.get(i));
           list.add(reportVo);
       }
        return list;
    }

    @Override
    public ReportClazzDataVo studentCountData() {
        ReportClazzDataVo reportClazzDataVo=new ReportClazzDataVo();
      List<Clazz>clist=clazzMapper.listall();
      List<String>clazzlist=new ArrayList<>();
      for(Clazz clazz:clist){
          clazzlist.add(clazz.getName());
      }
      List<Integer>count=new ArrayList<>();
      for(Clazz clazz:clist){
          count.add(studentMapper.countClazzData(clazz.getId()));
      }
      reportClazzDataVo.setClazzList(clazzlist);
      reportClazzDataVo.setDataList(count);
        return reportClazzDataVo;
    }
}
